package com.wwh.aop.aspectj;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Albert
 * @date 2024/8/27-8:54
 * @describe
 */
public class TestAopAspect {
    @Test
    public void calculatorByProxy(){
        //得到Spring容器
        ApplicationContext ioc = new ClassPathXmlApplicationContext("beans08.xml");

        //通过接口类型获取注入到容器的Calculator对象
        SmartAnimal bean = ioc.getBean(SmartAnimal.class);
        System.out.println("bean = " + bean);

        //查看容器返回的是什么类型？-> class com.sun.proxy.$Proxy16
        System.out.println("运行类型=" + bean.getClass());

        //运行
        bean.getSum(10, 2);
        bean.getSub(10, 2);

        //尝试使用非接口获取bean !! -> 已验证，此法行不通，因为getBean后会自动使用代理对象
        //Calculator calculator = (Calculator) ioc.getBean("calculator");
        //calculator.getSum(20, 6);
    }
}
